package org.core.tliaswebmanagement.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Slf4j
@Order(3)
@Component
//@Aspect
public class MyAspect4 {
    /*
    Spring用JoinPoint抽象了连接点,用它可获得方法执行时的相关信息
    @Around只能使用ProceedJoinPoint
    其他四种只能使用JointPoint
     */
    //前置通知
    @Before("@annotation(org.core.tliaswebmanagement.anno.LogOperation)")//在对应方法上加上相应注解即可
    public void before(JoinPoint joinPoint){
        log.info("MyAspect4 -> before ...");
        Object target=joinPoint.getTarget();
        log.info("获取目标对象: {}",target);
        String className=joinPoint.getClass().getName();
        log.info("获取目标对象类名: {}",className);
        String methodName=joinPoint.getSignature().getName();
        log.info("获取目标对象方法名: {}",methodName);
        Object[] args=joinPoint.getArgs();
        log.info("获取目标对象方法参数: {}", Arrays.toString(args));
    }

}
